var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var app = getApp();
var base64 = require('../../utils/Base64.js');
Page({
  data: {
    util: util,

    colorSet: '',

    mendianId: '',//门店id
    userCata: '',

    online: false
  },



  onLoad: function(options) {

    var that = this;
    console.log("页面参数：", options);
  
    let mendian_id = options.mendianid ? options.mendianid : '';
    
    wx.getSystemInfo({
      success: function(res) {
        var isIphone_x = (res.model.indexOf('iPhone X') >= 0);
        that.setData({
          isIphone_x: isIphone_x,
          mendianId: mendian_id,
          userCata: options.usercata
        });
      }
    });

    this.getGuiStatus();
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    var that = this;
    //获取颜色配置
    app.getColorSetData(function(color) {
      that.setData({
        colorSet: color
      })
      that.resetNavColor();
    });
  },

  onShow:function(){

  },

  //设置titlebar 样式
  resetNavColor: function() {
    var bg_color = '#f0f0f0';
    var fg_color = '#000000';
    if (this.data.colorSet) {
      bg_color = this.data.colorSet.titlebg;
      fg_color = this.data.colorSet.titlefont;
    }
    wx.setNavigationBarColor({
      frontColor: fg_color,
      backgroundColor: bg_color
    })
  },


  goAtherPage: function(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.link
    })
  },
  goAtherPageRedirect: function(e) {
    var url = e.currentTarget.dataset.link;
    wx.redirectTo({
      url: url
    })
  },

  //保存formId
  submitFormId: function(e) {
    app.saveFormId(e.detail.formId);
  },


  //获取服务器状态
  getGuiStatus: function () {
    var that = this;
    util.api({
      data: {
        "publickey": util.publiccode,
        "ac": "getguistatus",
      },
      success: function (responseData) {
        console.log("服务器状态：", responseData);
        that.setData({
          online: responseData.data.res
        })
      }
    });
  },
})